package com.xiaoxi.iteratormode.core.aggregate;

import com.xiaoxi.iteratormode.core.Aggregate;
import com.xiaoxi.iteratormode.core.Iterator;
import com.xiaoxi.iteratormode.core.domain.Book;
import com.xiaoxi.iteratormode.core.iterator.BookSelfIterator;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author xiaoxi
 * @ProjectName design_mode
 * @PackageName com.xiaoxi.iteratormode.core
 * @ClassName BookSelf
 * @Description TODO
 * @Date 2023/3/7 10:53
 * @Version 1.0
 */
public class BookSelf implements Aggregate {

    private List<Book> bookList;

    public BookSelf() {
        this.bookList = new ArrayList<>();
    }

    public BookSelf(int maxSize) {
        this.bookList = new ArrayList<>(maxSize);
    }

    public Book getChatAt(int index) {
        return this.bookList.get(index);
    }

    public int getLength() {
        return this.bookList.size();
    }

    public void appendBook(Book book) {
        this.bookList.add(book);
    }

    @Override
    public Iterator iterator() {
        return new BookSelfIterator(this);
    }
}
